/*
 * LinearInterpolationThermistor.hpp
 *
 * Copyright 2012 Pieter Agten
 *
 * This file is part of tltgen.
 *
 * tltgen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * tltgen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with tltgen.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file   LinearInterpolationThermistor.hpp
 * @author Pieter Agten (pieter.agten@gmail.com)
 * @date   11 feb 2013
 */

#ifndef LINEARINTERPOLATIONTHERMISTOR_HPP
#define LINEARINTERPOLATIONTHERMISTOR_HPP

#include <vector>
#include <boost/tuple/tuple.hpp>

#include "Thermistor.hpp"
#include "Resistance.hpp"
#include "Temperature.hpp"

namespace tltgen {

  using boost::tuple;

  class ThermistorTable;
  class LinearInterpolationThermistor : public Thermistor {
  public:
    LinearInterpolationThermistor(const shared_ptr<ThermistorTable>& thermistorTable);
    virtual ~LinearInterpolationThermistor();

    static bool compareFirst(tuple<double,double> t1, tuple<double,double> t2);

    static bool isValidThermistorTable(const shared_ptr<ThermistorTable>& thermistorTable);

    virtual bool isValidParameterIndex(unsigned int pi) const;
    virtual double getParameterValue(unsigned int pi) const;

    virtual bool isValidResistance(Resistance resistance) const;
    virtual Temperature getTemperature(Resistance resistance) const;

    virtual bool isValidTemperature(Temperature temperature) const;
    virtual Resistance getResistance(Temperature temperature) const;

    virtual void accept(ThermistorVisitor* visitor) const;

    virtual std::ostream &print(std::ostream &stream) const;

  protected:
    std::vector<tuple<Temperature, Resistance> > temperatureResistanceValues;
    std::vector<tuple<Resistance, Temperature> > resistanceTemperatureValues;
  };

}

#endif
